class ArticleModel {
  final int id;
  final String title;
  final String summary;
  final String content;
  final DateTime date;

  ArticleModel({
    required this.id,
    required this.title,
    required this.summary,
    required this.content,
    required this.date,
  });

  // 把 JSON 转成 Dart 对象
  factory ArticleModel.fromJson(Map<String, dynamic> json) => ArticleModel(
    id: json['id'],
    title: json['title'],
    summary: json['summary'],
    content: json['content'],
    date: DateTime.parse(json['date']),
  );

  // 把 Dart 对象转成 JSON（上传时用）
  Map<String, dynamic> toJson() => {
    'id': id,
    'title': title,
    'summary': summary,
    'content': content,
    'date': date.toIso8601String(),
  };
}
